package com.yn.admin.zy;


import com.yn.common.enums.AppointmentStatusEnum;
import com.yn.common.page.BasePage;
import com.yn.common.request.sc.PageParamRequest;
import com.yn.common.request.zy.ApptInfoQuery;
import com.yn.common.request.zy.ApptModifyInfoRequest;
import com.yn.common.request.zy.InstInfoQuery;
import com.yn.common.request.zy.InstModifyInfoRequest;
import com.yn.common.response.zy.DiagnosisInfoResponse;
import com.yn.common.response.zy.InstPageInfoResponse;
import com.yn.common.response.zy.InstitutionInfoResponse;
import com.yn.common.response.zy.DictResponse;
import com.yn.common.utils.genutils.CommonResult;
import com.yn.service.service.ISubscribeInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 * 预约信息表 前端控制器
 * </p>
 *
 * @author xuquanjun
 * @since 2025-07-07
 */
@RestController
@RequestMapping("/api/admin/zy/booking")
@Slf4j
@Api(tags = "预约信息表-管理端")
public class SubscribeInfoManageController {

    @Resource
    private ISubscribeInfoService subscribeInfoService;


    /**
     * 分页普通预约和住院预约
     * */
    @GetMapping("/diagnosis/page-list")
    @ApiOperation(value = "分页展示普通预约和住院预约")
    public CommonResult<BasePage<DiagnosisInfoResponse>> showInpatientPage(ApptInfoQuery query, PageParamRequest pageRequest) {
        log.info("开始执行展示普通预约和住院预约分页展示入参，{},{}", query, pageRequest);
        return CommonResult.success(subscribeInfoService.listApptPage(query,pageRequest));
    }

    /**
     * 查询普通预约或住院预约详情
     * */
    @GetMapping("/diagnosis/detail")
    @ApiOperation(value = "展示普通预约和住院预约详情")
    public CommonResult<DiagnosisInfoResponse> showInpatientDetail(@RequestParam @NotNull Integer id) {
        log.info("开始执行展示普通预约和住院预约详情入参，{}", id);
        return CommonResult.success(subscribeInfoService.showInpatientDetail(id));
    }

    /**
     * 取消预约——通用接口
     * */
    @PutMapping("/appointment/cancel")
    @ApiOperation(value = "用户取消预约")
    public CommonResult<String> apptAddCancel(@RequestParam @NotNull  Integer id) {
        log.info("开始执行用户取消普通预约入参，{}", id);
        subscribeInfoService.appointmentCancel(id, AppointmentStatusEnum.CANCELED.getCode(),null);
        return CommonResult.success("取消成功");
    }

    /**
     * 修改预约状态
     * @param id 预约id
     * @param status 预约状态
     * @return
     */
    @PostMapping("/modify/status")
    @ApiOperation(value = "修改预约状态")
    public CommonResult<String> modifyStatus(@RequestParam @NotNull Integer id
            ,@RequestParam @NotNull Integer status) {
        log.info("开始执行修改预约状态入参，id：{}，status:{}", id,status);
        subscribeInfoService.modifyStatus(id,status);
        return CommonResult.success("修改成功");
    }

    /**
     * 修改普通预约
     * */
    @PostMapping("/apptAdd/modify")
    @ApiOperation(value = "修改普通预约")
    public CommonResult<String> apptAddModify(@RequestBody @Validated ApptModifyInfoRequest request) {
        log.info("开始执行修改普通预约入参，{}", request);
        return CommonResult.success("修改成功",subscribeInfoService.diagnosisModify(request,null));
    }

    /**
     * 修改住院预约
     * */
    @PostMapping("/emergencyZyAdd/modify")
    @ApiOperation(value = "修改急诊预约")
    public CommonResult<String> emergencyZyAddModify(@RequestBody  @Validated ApptModifyInfoRequest request) {
        log.info("开始执行修改住院预约入参，{}", request);
        return CommonResult.success("修改成功",subscribeInfoService.diagnosisModify(request,null));
    }

    /**
     * 修改机构床位预约
     * */
    @PostMapping("/institution/modify")
    @ApiOperation(value = "修改机构床位预约")
    public CommonResult<String> institutionModify(@RequestBody @Validated InstModifyInfoRequest request) {
        log.info("开始执行修改机构床位预约入参，{}", request);
        return CommonResult.success("修改成功",subscribeInfoService.institutionModify(request,null));
    }

    /**
     * 删除预约接口——通用接口
     * */
    @DeleteMapping("/appointment/delete")
    @ApiOperation(value = "删除预约接口")
    public CommonResult<String> apptAddDelete(@RequestParam @NotNull Integer id) {
        log.info("开始执行删除预约入参，{}", id);
        subscribeInfoService.removeById(id);
        return CommonResult.success("删除成功");
    }

    /**
     * 分页展示机构预约
     * */
    @GetMapping("/institution/page-list")
    @ApiOperation(value = "分页展示机构预约")
    public CommonResult<BasePage<InstPageInfoResponse>> showInstitutionPage(InstInfoQuery query, PageParamRequest pageRequest) {
        log.info("开始执行展示普通预约和住院预约分页展示入参，{},{}", query, pageRequest);
        return CommonResult.success(subscribeInfoService.listInstPage(query,pageRequest));
    }

    /**
     * 机构床位预约详情
     * */
    @GetMapping("/institution/detail")
    @ApiOperation(value = "展示机构床位预约详情")
    public CommonResult<InstitutionInfoResponse> showInstitutionDetail(@RequestParam @NotNull Integer id) {
        log.info("开始执行展示床位预约详情入参，{}", id);
        return CommonResult.success(subscribeInfoService.showInstitutionDetail(id));
    }


    /**
     * 展示医保类型字典
     * */
    @GetMapping("/insurance/type")
    @ApiOperation(value = "展示医保类型字典")
    public CommonResult<List<DictResponse>> showInsuranceType(@RequestParam @NotNull String dictName) {
        log.info("开始执行展示医保类型字典");
        List<DictResponse> dictResponse = subscribeInfoService.showDictType(dictName);
        return CommonResult.success(dictResponse);
    }

    /**
     * 展示患者关系类型字典
     * */
    @GetMapping("/relation/type")
    @ApiOperation(value = "展示患者关系类型字典")
    public CommonResult<List<DictResponse>> showPatientRelationType(@RequestParam @NotNull String dictName) {
        log.info("开始执行展示患者关系类型字典");
        List<DictResponse> dictResponse = subscribeInfoService.showDictType(dictName);
        return CommonResult.success(dictResponse);
    }

}
